;;(function ($){
	//jQuery.validate form validate
	function bindjQueryValidateRule(){
		var checkRules={
				vd_phone:function(value,param){
					return /^1[3|4|5|8][0-9]\d{4,8}$/.test(value);
				},
				vd_account:function(value,param){
					return value && value.length > 0;
				},
				vd_azAZ09: function(value,element,param){
					var length = $.isArray( value ) ? value.length : this.getLength( value, element );
					return /^[a-zA-Z0-9 ]$/.test(value) && this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
				},
				vd_azAZ: function(value,element,param){
					var length = $.isArray( value ) ? value.length : this.getLength( value, element );
					return /^[a-zA-Z]$/.test(value) && this.optional( element ) || ( length >= param[ 0 ] && length <= param[ 1 ] );
				},
		};
		$.extend($.validator.methods,checkRules);
		var cnmsg = {
				required: "必选字段",
				remote: "请修正该字段",
				email: "请输入正确格式的电子邮件",
				url: "请输入合法的网址",
				date: "请输入合法的日期",
				dateISO: "请输入合法的日期 (ISO).",
				number: "请输入合法的数字",
				digits: "只能输入整数",
				creditcard: "请输入合法的信用卡号",
				equalTo: "请再次输入相同的值",
				accept: "请输入拥有合法后缀名的字符串",
				maxlength: "请输入一个长度最多是 {0} 的字符串",
				minlength: "请输入一个长度最少是 {0} 的字符串",
				rangelength: "请输入一个长度介于 {0} 和 {1} 之间的字符串",
				range: "请输入一个介于 {0} 和 {1} 之间的值",
				max: "请输入一个最大为 {0} 的值",
				min: "请输入一个最小为 {0} 的值",
				vd_phone: "请输入正确的电话号码!",
				vd_account: "请输入账号!",
				vd_azAZ09:"输入{0}到{1}个数字字母组合",
			    vd_azAZ:"输入{0}到{1}个字母组合",
				};
		$.extend($.validator.messages,cnmsg);
		//jQuery.validate default setting
		$.validator.setDefaults({
			submitHandler:function(form) {
	        	$(form).ajaxSubmit();
	    	},
			highlight: function ( element, errorClass, validClass ) {//校验错误时设置样式
				$( element ).parent( "div" ).addClass( "has-error" ).removeClass( "has-success" );
			},
			unhighlight: function (element, errorClass, validClass) {//校验正确时设置样式
				$( element ).parent( "div" ).addClass( "has-success" ).removeClass( "has-error" );
			},
			errorPlacement: function(error, element) {//设置错误提示位置  
			    error.appendTo(element.parent('div').parent('.form-group'));
			},
			errorClass: "error col-md-offset-2"
		});
	}
	bindjQueryValidateRule();
})(window.jQuery);
